<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://java.sun.com/jsp/jstl/core">


    <ui:composition template="/template.xhtml">
        <ui:define name="title">
            <h:outputText value="#{bundle.CreateExpensesTitle}"></h:outputText>
        </ui:define>
        <ui:define name="body">
            <h:outputScript name="js/jsfunctions.js" />
            <h:panelGroup id="messagePanel" layout="block">
                <h:messages errorStyle="color: red" infoStyle="color: green" layout="table"/>
            </h:panelGroup>
            <h:form id="form">
                <h:panelGrid columns="2">

                    <h:outputLabel value="#{bundle.CreateExpensesLabel_expenseDate}" for="expenseDate" />
                    <p:calendar value="#{expensesController.selected.expenseDate}" id="expenseDate" showOn="button" title="#{bundle.CreateExpensesTitle_expenseDate}" required="true" requiredMessage="#{bundle.CreateExpensesRequiredMessage_expenseDate}"/>

                    <h:outputLabel value="#{bundle.CreateExpensesLabel_project}" for="project" />
                    <h:selectOneMenu id="project" value="#{expensesController.selected.project}" title="#{bundle.CreateExpensesTitle_project}" >
                        <f:selectItems value="#{projectsController.itemsAvailableSelectOne}"/>
                    </h:selectOneMenu>

                    <h:outputLabel value="#{bundle.CreateExpensesLabel_task}" for="task" />
                    <h:inputText id="task" value="#{expensesController.selected.task}" title="#{bundle.CreateExpensesTitle_task}" required="true" requiredMessage="#{bundle.CreateExpensesRequiredMessage_task}"/>

                    <h:outputLabel value="#{bundle.CreateExpensesLabel_expenseType}" for="expenseType" />
                    <h:selectOneMenu id="expenseType" value="#{expensesController.selected.expenseType}" title="#{bundle.CreateExpensesTitle_expenseType}" required="true" requiredMessage="#{bundle.CreateExpensesRequiredMessage_expenseType}">
                        <f:selectItems value="#{expensesController.expensesTypes}"/>
                    </h:selectOneMenu>

                    <h:outputLabel value="#{bundle.CreateExpensesLabel_comment}" for="comment" />
                    <h:inputText id="comment" value="#{expensesController.selected.comment}" title="#{bundle.CreateExpensesTitle_comment}" required="false"/>   

                    <h:outputLabel value="#{bundle.CreateExpensesLabel_reimbursable}" for="reimbursable" />
                    <h:selectBooleanCheckbox id="reimbursable" value="#{expensesController.selected.reimbursable}" title="#{bundle.CreateExpensesTitle_reimbursable}" required="true" requiredMessage="#{bundle.CreateExpensesRequiredMessage_reimbursable}" />

                    <h:outputLabel value="#{bundle.CreateExpensesLabel_units}" for="units" />
                    <h:inputText id="units" onchange='computeTotal()' value="#{expensesController.selected.units}" title="#{bundle.CreateExpensesTitle_units}" />

                    <h:outputLabel value="#{bundle.CreateExpensesLabel_currency}" for="currency" />
                    <h:selectOneMenu id="currency" value="#{expensesController.selected.currency}" title="#{bundle.CreateExpensesTitle_currency}" required="true" requiredMessage="#{bundle.CreateExpensesRequiredMessage_currency}">
                        <f:selectItems value="#{currenciesController.itemsAvailableSelectOne}"/>
                    </h:selectOneMenu>

                    <h:outputLabel value="#{bundle.CreateExpensesLabel_expenseAmount}" for="expenseAmount" />
                    <h:inputText id="expenseAmount" onchange='computeTotal()' value="#{expensesController.selected.expenseAmount}" title="#{bundle.CreateExpensesTitle_expenseAmount}" required="true" requiredMessage="#{bundle.CreateExpensesRequiredMessage_expenseAmount}"/>

                    <c:if test="${type=='admin'}">
                    <h:outputLabel value="#{bundle.CreateExpensesLabel_employee}" for="employee" />
                        <h:selectOneMenu id="employee" value="#{expensesController.selected.employee}" title="#{bundle.CreateExpensesTitle_employee}" >
                            <f:selectItems value="#{employeesController.itemsAvailableSelectOne}"/>
                        </h:selectOneMenu>
                    </c:if>

                    <h:outputLabel value="#{bundle.CreateExpensesLabel_expenseTotal}" for="expenseTotal" />
                    <h:inputText id="expenseTotal" value="#{expensesController.selected.expenseTotal}" title="#{bundle.CreateExpensesTitle_expenseTotal}" required="false" readonly="true"/>

                </h:panelGrid>
                <br />
                <h:commandButton action="#{expensesController.createAndList}" type="submit" value="Save" />
                <h:commandButton action="#{expensesController.create}" type="submit" value="Save and New" />
            </h:form>
            <h:form>
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
                <h:commandButton rendered="${type=='admin'}" action="#{expensesController.prepareList}" value="#{bundle.CreateExpensesShowAllLink}" immediate="true"/>
                <h:commandButton rendered="${type=='user'}" action="#{expensesController.listUserExpenses}" value="#{bundle.CreateExpensesShowAllLink}" immediate="true"/>
                <h:button rendered="${type=='admin'}" value="Back to Home" outcome="/index" />
                <h:button rendered="${type=='user'}" value="Back to Home" outcome="/userhome"/>
            </h:form>
        </ui:define>
    </ui:composition>
</html>
